// 封装过滤器
let formatDate = value =>{//13位数时间戳转换
    let date = new Date(value);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
}
let region = value => {
    let dataId = '';
    switch (value) {
        case 1:
          dataId = "市直部门"
          break
        case 2:
          dataId = "镇街"
          break
        case 3:
            dataId = "协调监督"
            break
    }
    return dataId
}
let stated = value => {
    let dataId = '';
    switch (value) {
        case 0:
          dataId = "未处理"
          break
        case 1:
          dataId = "处理中"
          break
        case 2:
            dataId = "已评价"
            break
        case 3:
            dataId = "已完成"
            break
        case -1:
            dataId = "退回"
            break
    }
    return dataId
}
let Twostated = value => {
    let dataId = '';
    switch (value) {
        case 0:
          dataId = "未处理"
          break
        case 1:
          dataId = "处理中"
          break
        case 2:
            dataId = "已完成"
            break
        case 3:
            dataId = "已完成"
            break
        case -1:
            dataId = "退回"
            break
    }
    return dataId
}
let userd = value => {
    let dataId = '';
    switch (value) {
        case 2:
          dataId = "超级管理员"
          break
        case 1:
          dataId = "管理员"
          break
        case 0:
            dataId = "普通管理员"
            break
    }
    return dataId
}
let formatDated = value => {//10位时间戳转换
    if(value == '0'){
        return " "
    }else{
      let date = new Date(parseInt(value) * 1000);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let minute = date.getMinutes();
    //   let second = date.getSeconds();
      minute = minute < 10 ? "0" + minute : minute;
    //   second = second < 10 ? "0" + second : second;
      return y + '-' +m + "-" + d + "  " + h + ":" + minute
    }
}
let year = value => {//10位时间戳转换
    if(value == '0'){
        return " "
    }else{
        let date = new Date(parseInt(value) * 1000);
        let y = date.getFullYear();
        return y
    }
}     
// 根据身份证号码判断男女
let sexIdcardFilter = value => {
    if (!value) {
    return "";
    } else {
    let data = value.substr(16, 1) % 2 === 1 ? "男" : "女";
    return data;
    }
};

// 身份证号脱敏('331082199708094687' 转换成 '33108219********87') 第8位开始替换8个
let IDcardHide = num => {
    let data = num.replace(/(\d{8})\d{8}(\d*)/, "$1********$2");
    return data;
};

// 手机号脱敏('13912345678' 转换成 '139****5678') 第3位开始替换4个
let telHide = num => {
    let data = num.replace(/(\d{3})\d{4}(\d*)/, "$1****$2");
    return data;
};

// 姓名脱敏(小明 转换成 *明   李小明 转换成 李*明   欧阳小明 转换成 欧**明)
let nameHide = name => {
    if (name.length === 2) {
    return new Array(name.length).join("*") + name.substr(-1);
    } else {
    return (
        name.substr(0, 1) + new Array(name.length - 1).join("*") + name.substr(-1)
    );
    }
};

//把数字格式化为两位小数
let twoDecimals = number => {
    if (isNaN(number)) {
    return "0.00";
    } else {
    return parseFloat(number).toFixed(2);
    }
};

export default {
    userd,
    stated,
    year,
    formatDate,
    formatDated,
    sexIdcardFilter,
    IDcardHide,
    telHide,
    nameHide,
    twoDecimals,
    region,
    Twostated
};